@extends('Home.User.Common.layout')
@section('title')
    指定MAC信息登录_设置
@endsection
@section('content')
    <!--  content  -->
    <main class="common_content">
        <div class="container">
            <div class="ct_main">
                @include('Home.User.Set.Common.set_menu')
                <ul class="nav-items1 nav-items2 w999" id="tab-content2">
                    <!--基本设置-->
                    <li class="basic-sets active">
                        <div class="selector-head">
                            <h2>基本设置</h2>
                        </div>
                        <!--指定MAC信息登录-->
                        <ul class="basic-sets-ul">
                            <li>
                                <h2 class="basic-title">
                                    指定MAC信息登录：
                                <form class="layui-form" style="display: inline-block" action="" id="form-user" lay-filter="form-user">
                                    <label for="mac">
                                        <input type="checkbox" name="mac" lay-filter="mac" lay-skin="switch" lay-text="开启|关闭" @if($mac_flag->val) checked @endif>
                                        <span style="color: #999; margin-left: 3px;">（在MAC信息设置里录入的MAC电脑才能录入）</span>
                                    </label>
                                </form>
                                    <a href="#" class="rt" id="add_mac" title="添加" onclick="open_button('{{route('mac_add')}}','添加',600,400)"><i class="icon icon-add"></i></a>
                                </h2>
                                <div class="layui-form">
                                    <table class="layui-table" id="mac_table">
                                        <thead>
                                        <tr>
                                            <th>序号</th>
                                            <th>MAC地址</th>
                                            <th>所属人员</th>
                                            <th width="200">备注</th>
                                            <th>最后修改人</th>
                                            <th>最后修改时间</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($mac_list as $k => $v)
                                        <tr>
                                            <td>{{$v->id}}</td>
                                            <td>{{$v->mac}}</td>
                                            <td>{{$v->username}}</td>
                                            <td>{{$v->describe}}</td>
                                            <td>{{$v->mac_user?$v->mac_user->username:''}}</td>
                                            <td>{{$v->mac_time?date('Y-m-d H:i:s',$v->mac_time):''}}</td>
                                            <td>
                                                <input type="button" class="check-btn" value="编辑" lay-event="edit" onclick="open_button('{{route('mac_edit',$v->id)}}','编辑',600,300)">
                                                <input type="button" class="check-btn" value="删除" lay-event="del" onclick="del(this,'{{route('mac_del',$v->id)}}')">
                                            </td>
                                        </tr>
                                        @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </main>
@endsection
@section('footer')
    <style>
        .layui-form-switch{
            margin-top: 0 !important;
        }
    </style>
    <script>
        layui.use(['form', 'layer'], function() {
            var form = layui.form;

            form.on('switch(mac)', function(data){
                var data = {mac:Number(data.elem.checked)}; //开关是否开启，true或者false
                $.ajax({
                    type: 'post',
                    data: data,
                    url: '{{route('config_set')}}',
                    dataType: 'json',
                    success: function(data){
                        if(data.code){
                        }else{
                            layer.msg(data.msg,{icon: 5,time:1000});
                        }
                    },
                    error:function() {
                        layer.msg('服务器错误!',{icon: 5,time:1000});
                    }
                });


            });
        });

        function del(obj,url) {
            layer.confirm("你确定删除吗？此操作不能撤销！", {icon: 3, title:'提示'},
                function(index){//确定回调
                    $.ajax({
                        type: 'get',
                        url: url,
                        dataType: 'json',
                        success: function(data){
                            if(data.code){
                                layer.close(index);
                                $(obj).parent().parent().remove();
                            }else{
                                layer.msg(data.msg,{icon: 5,time:1000});
                            }
                        },
                        error:function() {
                            layer.msg('服务器错误!',{icon: 5,time:1000});
                        }
                    });
                },function (index) {//取消回调
                    layer.close(index);
                }
            );
        }
    </script>
@endsection
@include('Home.User.Common._footer')